//
//  QKHttpManager.h
//  SmartTeaching
//
//  Created by yangqingluo on 15/9/6.
//  Copyright (c) 2015年 yangqingluo. All rights reserved.
//

#import <Foundation/Foundation.h>

#define urlIP @"http://120.25.146.222"
#define urlPort 8080

#define urlAddress [NSString stringWithFormat:@"%@/ufan-api/v1/",urlIP]

#define responseTime 10.0

#define QKHTTP_SUCCESS	            	200	//成功
#define QKHTTP_ERROR            	 	400	//出错


#define QKHTTP_ProductTypeAll         @"all"
#define QKHTTP_ProductTypeHot         @"hot"
#define QKHTTP_ProductTypeReserve     @"reserve"

@interface NSData (Base64)
- (NSString*)base64EncodingWithLineLength:(unsigned int)lineLength;
- (NSString *)getImageType;
- (BOOL)isJPG;
- (BOOL)isPNG;
- (BOOL)isGIF;
@end


typedef void(^NetworkFinishedFunc)(NSObject *object, NSError *error);

typedef enum {
    CouponTypeNormal          = 1,
    CouponTypeAllOnSale       = 3,
    CouponTypePartOnSale      = 4,
}CouponType;

typedef enum {
    OrderTypeAll          = 1,
    OrderTypeNotPay          = 2,
    OrderTypeWaiting          = 3,
    OrderTypeSended          = 4,
    OrderTypeDone          = 5,
}OrderType;


@interface QKHttpManager : NSObject

NSString *stringFromOrderType(OrderType type);
UIColor *colorFromOrderType(OrderType type);

//登录
+ (void)loginWithUsername:(NSString *)username password:(NSString *)password completion:(NetworkFinishedFunc)completion;

//获取手机验证码
+ (void)getIdentifyCodeWithPhone:(NSString *)phoneNum andIsRegistered:(BOOL)isRegistered completion:(NetworkFinishedFunc)completion;

//注册
+ (void)registWithPhone:(NSString *)phoneNum password:(NSString *)password identifyCode:(NSString *)identifyCode andToken:(NSString *)token completion:(NetworkFinishedFunc)completion;

//获取商品列表
+ (void)getProductsWithPage:(NSUInteger)pageNo type:(NSString *)type shopID:(NSString *)shopID categoryID:(NSString *)categoryID completion:(NetworkFinishedFunc)completion;

//获取商品详情
+ (void)getProductWithProductID:(NSString *)productID couponType:(CouponType)type completion:(NetworkFinishedFunc)completion;

//下订单
+ (void)checkOrdersWithAddress:(NSString *)addressId product:(UFShoppingProduct *)product invoice:(UFInvoice *)invoice completion:(NetworkFinishedFunc)completion;

//更新收货地址
+ (void)updateAddress:(UFAddressInfo *)addressInfo completion:(NetworkFinishedFunc)completion;

//获取收货地址列表
+ (void)getAddressCompletion:(NetworkFinishedFunc)completion;

//获取默认收货地址
+ (void)getDefaultAddressCompletion:(NetworkFinishedFunc)completion;

//获取订单列表
+ (void)getOrdersWithPage:(NSUInteger)pageNo type:(OrderType)type completion:(NetworkFinishedFunc)completion;

//删除收货地址
+ (void)deleteAddress:(NSString *)idString completion:(NetworkFinishedFunc)completion;

//支付订单
+ (void)payOrder:(NSString *)orderId paymentID:(NSString *)paymentId payStyleID:(NSString *)payID completion:(NetworkFinishedFunc)completion;

//确认订单
+ (void)sureOrder:(NSString *)idString completion:(NetworkFinishedFunc)completion;

@end
